package com.neusoft.yuejian_6.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.yuejian_6.activity.ShowDetailActivity;
import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.javabean.Show;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Mao on 2017/10/8.
 */

public class ShowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContex;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public ShowAdapter(Context mContext, List mDataList) {
        this.mContex = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).
                inflate(R.layout.cardview_show, parent, false);
        return new ShowAdapter.ViewHolder(v);
    }


    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Show entity = (Show) mDataList.get(position);
        if (null == entity)
            return;
        ShowAdapter.ViewHolder viewHolder = (ShowAdapter.ViewHolder) holder;
        //   viewHolder.food_level.setRating(entity.getLevel());
        viewHolder.s_content.setText(entity.getS_content());
        viewHolder.s_address.setText(entity.getS_address());
        // System.out.print("Train_name");
        String s_pic = "http://10.0.2.2/neu1_yuejian/Public/Admin/photo/" + entity.getS_pic();
        System.out.print("s_pic");
        if (!s_pic.equals("")) {
            Picasso.with(mContex).load(s_pic).into(viewHolder.s_pic);

        String s_pic2= "http://10.0.2.2/neu1_yuejian/Public/Admin/photo/" + entity.getS_pic2();
            System.out.print("s_pic2");
         if  (!s_pic2.equals("")) {
             Picasso.with(mContex).load(s_pic2).into(viewHolder.s_pic2);

         }

        }
        // Picasso.with(mContex).load(entity.getTrain_id_id()).into(viewHolder.Train_pic);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putInt("s_id", entity.getS_id());
                bundle.putString("s_content", entity.getS_content());
                bundle.putString("s_address", entity.getS_address());
                bundle.putString("s_date", entity.getS_date());
                bundle.putString("s_pic", entity.getS_pic());
                bundle.putString("s_pic2", entity.getS_pic2());
                bundle.putString("s_pic3", entity.getS_pic3());
               // bundle.putString("s_pic1", entity.getS_pic1());
                Intent intent = new Intent(mContex, ShowDetailActivity.class);
                intent.putExtras(bundle);
                mContex.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        // ImageView food_thumb;
        TextView s_address;
        ImageView s_pic;
        TextView s_content;
        ImageView s_pic2;
        //RatingBar food_level;

        public ViewHolder(View itemView) {
            super(itemView);
            s_content = (TextView) itemView.findViewById(R.id.s_content);
            s_address = (TextView) itemView.findViewById(R.id.s_address);
            s_pic = (ImageView) itemView.findViewById(R.id.s_pic);
            s_pic2 = (ImageView) itemView.findViewById(R.id.s_pic2);
            //   food_thumb = (ImageView) itemView.findViewById(R.id.food_thumb);
            // food_info = (TextView) itemView.findViewById(R.id.food_info);
            // food_level = (RatingBar) itemView.findViewById(R.id.food_level);
        }
    }
}